<%@ page import="com.gmono.managers.User" %><%--
  Created by IntelliJ IDEA.
  User: gaozijian
  Date: 2018/12/31
  Time: 18:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/printAllParamter.jsp"%>
<%
    request.setCharacterEncoding("UTF-8");
    User u=new User();
    u.setUsername(request.getParameter("username"));
    u.getInfo();
    u.setPhonenumber(request.getParameter("usertel"));
    u.setName(request.getParameter("truename"));

    String err=null;

    String oldp=request.getParameter("old_password");
    //如果有修改密码
    if(!oldp.isEmpty()) {
        String p = request.getParameter("password");
        String np = request.getParameter("new_password");

        try {
            assert p.equals(np) : "错误，重复密码不一致";
            assert u.getPassword().equals(oldp) : "错误，旧密码输入错误";
        } catch (AssertionError e) {
            err = e.getMessage();
        }
        u.setPassword(p);
    }

    if(u.update()) out.print(true);
    else err="错误，更新失败";

    if(err!=null)
    {
        out.print(String.format("<h1>%s</h1>", err));
    }

%>
<%if(err==null){%>
<script>
    alert("更新成功");
    self.location=document.referrer;
</script>
<%}%>

